package d1123;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class Demo03List03 {
    public static void main(String[] args) {


        List list = new ArrayList();//多态
        list.add("贾宝玉");
        list.add("林黛玉");
        list.add("薛宝钗");
        list.add("王熙凤");
      //增强for
        for (Object o :list){
            System.out.println(o+"~~~~~~~");

        }
        //集合的forEach()方法
        System.out.println("集合的forEach()方法--------");
        list.forEach(s-> System.out.println(s));
        //迭代器
        System.out.println("迭代器遍历~~~~~~~");
        Iterator it = list.iterator();
        while(it.hasNext()){
            System.out.println(it.next());
        }

        //传统for循环遍历
        for(int i=0;i<list.size();i++){
            System.out.println(list.get(i));
        }


    }

}